let $results := doc("results")
return 
	for $xp in $results//xp
	return 
		let $history := db:open(string($xp/@id), "historyResults.xml")
		return	
			insert node 
				<history date="{data($xp/date/text())}">
				{$xp/users}
				</history>
			 into $history/historyResults